﻿#pragma once

#include <vtkActor.h>
#include <vtkActorCollection.h>
#include <vtkAreaPicker.h>
#include <vtkCallbackCommand.h>
#include <vtkCellPicker.h>
#include <vtkCommand.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkMath.h>
#include <vtkObjectFactory.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkCubeSource.h>
#include <vtkCylinderSource.h>
#include <vtkOutlineFilter.h>

#include <unordered_map>
#include <vector>
#include <memory>

// 拾取模式枚举
enum class PickMode
{
    NONE,
    VOLUME,
    FACE,
    EDGE,
    POINT
};

// 高亮管理器类
class SelectionManager
{
public:
    SelectionManager();

    // 添加高亮对象
    void AddSelectedActor(vtkActor* actor, PickMode mode);

    // 移除高亮
    void RemoveSeletedActor(vtkActor* actor);

    // 清除所有高亮
    void ClearAllSelectedActors();

    // 设置高亮颜色
    void SetHighlightColor(double r, double g, double b);

    // 设置Mapper偏移
    void SetMapperOffset(vtkActor* actor, double offset);

    // 重置Mapper偏移
    void ResetMapperOffset(vtkActor* actor);

    // 获取选中的Actor集合
    vtkActorCollection* GetSelectedActors() const;
    std::vector<vtkActor*> GetSelectedActors();

    // 新增方法：检查Actor是否被高亮
    bool IsActorHighlighted(vtkActor* actor) const;

private:
    void SetHighlight(vtkActor* actor, PickMode mode);
    void RestoreOriginalProperty(vtkActor* actor);
    void UpdateAllHighlights();

    struct SelectedActorInfo
    {
        vtkSmartPointer<vtkProperty> originalProperty;
        PickMode mode;
    };

    std::unordered_map<vtkActor*, SelectedActorInfo> m_actorOrigInfoMap;
    vtkSmartPointer<vtkActorCollection> m_selectedActors;
    vtkSmartPointer<vtkProperty> m_selectedProperty;
};
